import request from "@/utils/request";
const eventContext = "/event"; // 事件
const eventContextTT = "/ttevent"; // 事件
const adminContext = "/admin"; // 公共
const videoContext = "/video-video"; // 视频
const videoContextTT = "/ttvideo"; // 视频

import store from "@/store/index";
/**
 * 判断当前用户是否为租户用户
 *
 * @returns {boolean} 返回布尔值，表示当前用户是否为租户用户
 */
export function isTenant() {
  return !!store?.getters?.userInfo?.tenantId;
}
/**
 * 获取应用版本码
 *
 * @returns {string} 应用版本码
 */
export function appVerCode() {
  return store?.getters?.userInfo?.chooseAppVerCode;
}

/**
 * 获取事件上下文或事件上下文TT
 *
 * @returns {Object} 事件上下文或事件上下文TT
 */
function eventContextOrTT() {
  return isTenant() ? eventContext : eventContextTT;
}

/* 客户视角 */
/* 通过告警工单ID获取处理环节信息 */
export function getRecordByOrderId(data) {
  return request({
    url: eventContext + `/alarm/order/getRecordByOrderId`,
    method: "post",
    data,
  });
}
/**
 * 获取告警列表详情
 * statusStr / + 0虚假告警完结 1 待研判    2 派单中    3抢单中    4 待处置  5待核实 6工单完成  7重复告警完成
 */
export function getOrderInfo(data) {
  return request({
    url: eventContext + `/alarm/order/getOrderInfo`,
    method: "post",
    data,
  });
}
/* 事件新增收藏*/
export function addWarningOrderCollection(data) {
  return request({
    url: eventContext + "/alarm/order/collection/addWarningOrderCollection",
    method: "post",
    data,
  });
}

/* 事件取消收藏 */
export function delWarningOrderCollection(data) {
  return request({
    url: eventContext + "/alarm/order/collection/delWarningOrderCollection",
    method: "post",
    data,
  });
}

/* 查询领导批示列表 */
export function getLeaderAuditList(data) {
  return request({
    url: eventContext + "/alarm/order/getLeaderAuditList",
    method: "post",
    data,
  });
}

/* 查询重复告警列表接口 */
export function getOrderListForDuplication(data) {
  return request({
    url: eventContext + "/alarm/order/getOrderListForDuplication",
    method: "post",
    data,
  });
}

/* 查询右侧待研判告警列表接口 ^*/
export function getAlarmListForBigScreen(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: `${eventContext}/alarm/order/getAlarmListForBigScreen?pageSize=${data.pageSize}&pageNum=${data.pageNum}`,
    method: "post",
    data,
  });
}

/* 查询右侧待研判告警列表接口 ^*/
export function qryWarningOrderCollectionForBigScreen(data) {
  return request({
    url: `${eventContext}/alarm/order/collection/qryWarningOrderCollectionForBigScreen?pageSize=${data.pageSize}&pageNum=${data.pageNum}`,
    method: "post",
    data,
  });
}

/* 调用告警研判接口 */
export function checkAlarmOrder(data) {
  return request({
    url: eventContext + "/alarm/order/checkAlarmOrder",
    method: "post",
    data,
  });
}
/* 提交转领导批示接口 */
export function addLeaderAudit(data) {
  return request({
    url: eventContext + "/alarm/orderleaderaudit/addLeaderAudit",
    method: "post",
    data,
  });
}
/* 告警事件调度接口 */
export function sendAlarmOrder(data) {
  return request({
    url: eventContext + "/alarm/order/sendAlarmOrder",
    method: "post",
    data,
  });
}
/*  */
export function uploadImg(data) {
  return request({
    url: eventContext + "/upload/img",
    method: "post",
    data,
  });
}
/*  */
export function uploadVideo(data) {
  return request({
    url: eventContext + "/upload/video",
    method: "post",
    data,
  });
}
/* 处置信息删除图片 */
export function uploadDelete(data) {
  return request({
    url: eventContext + "/upload/delete",
    method: "post",
    data,
  });
}
/* 告警事件处置接口 */
export function submitProcessOrder(data) {
  return request({
    url: eventContext + "/alarm/processorder/submitProcessOrder",
    method: "post",
    data,
  });
}
/* 告警核实接口 */
export function submitOrderApproveInfo(data) {
  return request({
    url: eventContext + "/alarm/orderApprove/submitOrderApproveInfo",
    method: "post",
    data,
  });
}
/* 回退接口 */
export function rollBack(data) {
  return request({
    url: eventContext + "/alarm/processorder/rollBack",
    method: "post",
    data,
  });
}
/* 查询告警类型集合 */
export function findOrderAlarm(data) {
  return request({
    url: eventContext + "/alarm/type/findOrderAlarm",
    method: "post",
    data,
  });
}
export function findAlarmSourceAll(query) {
  return request({
    url: "/event/alarm/flowconfig/findAlarmSourceAll",
    method: "post",
    data: query,
  });
}
/* 查询人员通用接口 */
export function getUserByTenantIdNew(data) {
  return request({
    url: eventContext + `/video/base/getLeaderByTenantId`,
    method: "post",
    data,
  });
}
/* 查询客户组织树 */
export function getCustOrganTreeNew(data) {
  return request({
    url: "/admin/system/tenantDept/listSubsetDept",
    method: "post",
    data,
  });
}
/* 播放历史视频 */
export function getVideoPlaybackUrl(data) {
  return request({
    url: videoContext + "/video/getVideoPlaybackUrl",
    method: "post",
    data,
  });
}
/* 提交领导批示 */
export function updateLeaderAudit(data) {
  return request({
    url: eventContext + "/alarm/order/updateLeaderAudit",
    method: "post",
    data,
  });
}
/* 获取区域*/
export function getRegion(data) {
  return request({
    url: adminContext + "/video/getRegion",
    method: "post",
    data,
  });
}
/* 认领提交 */
export function grabProcessOrder(data) {
  return request({
    url: eventContext + "/alarm/processorder/grabProcessOrder",
    method: "post",
    data,
  });
}

/* 铁塔视角 */
/* 通过告警工单ID获取处理环节信息 */
export function getRecordByOrderIdTT(data) {
  return request({
    url: eventContextTT + `/alarm/order/getRecordByOrderId`,
    method: "post",
    data,
  });
}
/**
 * 获取告警列表详情
 * statusStr / + 0虚假告警完结 1 待研判    2 派单中    3抢单中    4 待处置  5待核实 6工单完成  7重复告警完成
 */
export function getOrderInfoTT(data) {
  return request({
    url: eventContextTT + `/alarm/order/getOrderInfo`,
    method: "post",
    data,
  });
}
/* 事件新增收藏*/
export function addWarningOrderCollectionTT(data) {
  return request({
    url: eventContextTT + "/alarm/order/collection/addWarningOrderCollection",
    method: "post",
    data,
  });
}

/* 事件取消收藏 */
export function delWarningOrderCollectionTT(data) {
  return request({
    url: eventContextTT + "/alarm/order/collection/delWarningOrderCollection",
    method: "post",
    data,
  });
}

/* 查询领导批示列表 */
export function getLeaderAuditListTT(data) {
  return request({
    url: eventContextTT + "/alarm/order/getLeaderAuditList",
    method: "post",
    data,
  });
}

/* 查询重复告警列表接口 */
export function getOrderListForDuplicationTT(data) {
  return request({
    url: eventContextTT + "/alarm/order/getOrderListForDuplication",
    method: "post",
    data,
  });
}

/* 查询右侧待研判告警列表接口 */
export function getAlarmListForBigScreenTT(data) {
  return request({
    url: `${eventContextTT}/alarm/order/getAlarmListForBigScreen?pageSize=${data.pageSize}&pageNum=${data.pageNum}`,
    method: "post",
    data,
  });
}

/* 查询右侧待研判告警列表接口 */
export function qryWarningOrderCollectionForBigScreenTT(data) {
  return request({
    url: `${eventContextTT}/alarm/order/collection/qryWarningOrderCollectionForBigScreen?pageSize=${data.pageSize}&pageNum=${data.pageNum}`,
    method: "post",
    data,
  });
}

/* 调用告警研判接口 */
export function checkAlarmOrderTT(data) {
  return request({
    url: eventContextTT + "/alarm/order/checkAlarmOrder",
    method: "post",
    data,
  });
}
/* 提交转领导批示接口 */
export function addLeaderAuditTT(data) {
  return request({
    url: eventContextTT + "/alarm/orderleaderaudit/addLeaderAudit",
    method: "post",
    data,
  });
}
/* 告警事件调度接口 */
export function sendAlarmOrderTT(data) {
  return request({
    url: eventContextTT + "/alarm/order/sendAlarmOrder",
    method: "post",
    data,
  });
}
/* 告警事件处置接口 */
export function submitProcessOrderTT(data) {
  return request({
    url: eventContextTT + "/alarm/processorder/submitProcessOrder",
    method: "post",
    data,
  });
}
/* 告警核实接口 */
export function submitOrderApproveInfoTT(data) {
  return request({
    url: eventContextTT + "/alarm/orderApprove/submitOrderApproveInfo",
    method: "post",
    data,
  });
}
/* 回退接口 */
export function rollBackTT(data) {
  return request({
    url: eventContextTT + "/alarm/processorder/rollBack",
    method: "post",
    data,
  });
}
/* 查询告警类型集合 */
export function findOrderAlarmTT(data) {
  return request({
    url: eventContextTT + "/alarm/type/findOrderAlarm",
    method: "post",
    data,
  });
}
/* 查询人员通用接口 */
export function getUserByTenantIdNewTT(data) {
  return request({
    url: eventContextTT + `/video/base/getLeaderByTenantId`,
    method: "post",
    data,
  });
}

/* 播放历史视频 */
export function getVideoPlaybackUrlTT(data) {
  return request({
    url: videoContextTT + "/video/getVideoPlaybackUrl",
    method: "post",
    data,
  });
}
/* 提交领导批示 */
export function updateLeaderAuditTT(data) {
  return request({
    url: eventContextTT + "/alarm/order/updateLeaderAudit",
    method: "post",
    data,
  });
}
/* 认领提交 */
export function grabProcessOrderTT(data) {
  return request({
    url: eventContextTT + "/alarm/processorder/grabProcessOrder",
    method: "post",
    data,
  });
}
/* 告警详情下历史告警列表 */
export function getHistoryAlarm(params) {
  return request({
    url:
      eventContextOrTT() +
      "/alarm/order/getOrderListByDeviceChannelAndPresetId",
    method: "post",
    data: params,
  });
}
/* 图片对比 */
export function alarmImageCompare(query) {
  return request({
    url: "/video-video/video/patrol/queryPresetImgJob",
    method: "post",
    data: query,
  });
}

/**
 * 查询预置列表图片任务
 *
 * @param query 查询参数
 * @returns Promise 对象
 */
export function queryPresetListImgJob(query) {
  return request({
    url: "/video-video/video/patrol/sdk/queryPresetListImgJob",
    method: "post",
    data: query,
  });
}
